﻿namespace MyTRCP.Common.MyProtocol
{
    public class ClientAuthPayload : BitWalkableObj//client->bridge
    {
        public ushort ClientIdAuthResponseLength { get; set; }
        public byte[] ClientIdAuthResponse { get; set; } = [];
        public ushort BridgeIdAuthChallengeLength { get; set; }
        public byte[] BridgeIdAuthChallenge { get; set; } = [];
        public ClientAuthPayload() { }
        public ClientAuthPayload(byte[] data) : base(data) { }
        public override BitWalker ReadFromBitWalker(BitWalker bw)
        {
            ClientIdAuthResponseLength = (ushort)bw.ReadBits(16);
            ClientIdAuthResponse = bw.ReadBytes(ClientIdAuthResponseLength);
            BridgeIdAuthChallengeLength = (ushort)bw.ReadBits(16);
            BridgeIdAuthChallenge = bw.ReadBytes(BridgeIdAuthChallengeLength);
            return bw;
        }

        public override BitWalker WriteToBitWalker(BitWalker bw)
        {
            return bw
                .WriteBits(ClientIdAuthResponseLength, 16)
                .WriteBytes(ClientIdAuthResponse)
                .WriteBits(BridgeIdAuthChallengeLength, 16)
                .WriteBytes(BridgeIdAuthChallenge);
        }
    }
}